package la.foton.atividade.controller;

import java.util.Collection;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import la.foton.atividade.entity.CasoDeUso;
import la.foton.atividade.service.CasoDeUsoService;
import org.primefaces.event.RowEditEvent;

@ManagedBean(name = "casoDeUsoBean")
@RequestScoped
public class CasoDeUsoBean extends BaseBean {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

   @ManagedProperty("#{casoDeUsoService}")
   private CasoDeUsoService casoDeUsoService;
   private List<CasoDeUso> listAll;
   private CasoDeUso casoDeUso;

   public CasoDeUsoBean()
   {

	}

   @PostConstruct
   private void init()
   {
      casoDeUso = new CasoDeUso();
   }

   public void incluir()
   {
      casoDeUsoService.create(casoDeUso);
      atualizarListaCasoDeUso();
		clean();
      addInfoMessage("Caso de Uso  incluído com sucesso.");
	}


   public void atualizarListaCasoDeUso()
   {
      listAll = casoDeUsoService.getAll();
   }

   public Collection<CasoDeUso> getValuesComboCasoDeUso()
   {
      return getListAll();
   }

	public void clean() {
      /*
       * this.nomeCliente = ""; this.nomeProjeto = "";
       */
	}

	public void onEdit(RowEditEvent event) {
      CasoDeUso casoDeUso = (CasoDeUso) event.getObject();
      casoDeUsoService.update(casoDeUso);
      atualizarListaCasoDeUso();
      addInfoMessage("Caso de Uso alterado com sucesso!!");
	}

	public void onCancel(RowEditEvent event) {
      CasoDeUso casoDeUso = (CasoDeUso) event.getObject();
      casoDeUsoService.deleteById(casoDeUso);
      atualizarListaCasoDeUso();
      addInfoMessage(casoDeUso.getId() + " excluido");
	}

   /**
    * Recupera o valor do atributo casoDeUsoService
    * 
    * @return o casoDeUsoService
    */
   public CasoDeUsoService getCasoDeUsoService()
   {
      return casoDeUsoService;
   }

   /**
    * Atribui o novo valor de casoDeUsoService
    * 
    * @param casoDeUsoService casoDeUsoService que será atribuído
    */
   public void setCasoDeUsoService(CasoDeUsoService casoDeUsoService)
   {
      this.casoDeUsoService = casoDeUsoService;
   }


   /**
    * Recupera o valor do atributo listAllCsu
    * 
    * @return o listAllCsu
    */
   public List<CasoDeUso> getListAll()
   {
      if (listAll == null)
      {
         atualizarListaCasoDeUso();
      }

      return listAll;
   }


   /**
    * Atribui o novo valor de listAllCsu
    * 
    * @param listAllCsu listAllCsu que será atribuído
    */
   public void setListAll(List<CasoDeUso> listAll)
   {
      this.listAll = listAll;
   }


   /**
    * Recupera o valor do atributo casoDeUso
    * 
    * @return o casoDeUso
    */
   public CasoDeUso getCasoDeUso()
   {
      return casoDeUso;
   }

   /**
    * Atribui o novo valor de casoDeUso
    * 
    * @param casoDeUso casoDeUso que será atribuído
    */
   public void setCasoDeUso(CasoDeUso casoDeUso)
   {
      this.casoDeUso = casoDeUso;
   }


}
